<!-- subpkg_consult/department/department -->
<script lang="ts" setup>
  import { departmentListApi } from '@/apis/consult'
  import type { DepartData } from '@/types/consult'
  import { computed, ref } from 'vue'

  // 1. 科室列表
  const departmentList = ref<DepartData[]>([])
  // 科室列表
  async function getDepartmentList() {
    // 科室列表接口
    const data = await departmentListApi()
    // 渲染列表数据
    departmentList.value = data
  }

  // 获取科室列表
  getDepartmentList()
  // 点击高亮变量
  const activeIndex = ref(0)
  const childList = computed(() => {
    return departmentList.value[activeIndex.value]?.child
  })

  // 接收父传子
  defineProps<{ type: string; illnessType: string }>()
</script>

<template>
  <view class="department-page">
    <scroll-view scroll-y class="department-primary">
      <view
        v-for="(item, index) in departmentList"
        :key="item.id"
        class="department-item"
        :class="{
          active: activeIndex === index,
        }"
        @click="activeIndex = index"
      >
        {{ item.name }}
      </view>
    </scroll-view>
    <scroll-view class="department-secondary">
      <navigator
        hover-class="none"
        :url="`/subpkg_consult/description/description?type=${type}&illnessType=${illnessType}&depId=${item.id}`"
        v-for="item in childList"
        class="department-item"
      >
        {{ item.name }}
      </navigator>
    </scroll-view>
  </view>
</template>

<style lang="scss">
  @import './department.scss';
</style>
